Skip to content

feat: add datadog_tag_indexing_rule, _exemption, and _order resources#3863

Draft
chuck wants to merge 1 commit into
masterfrom
chuck.hagenbuch/tag-indexing-rule-resources
Draft

feat: add datadog_tag_indexing_rule, _exemption, and _order resources#3863
chuck wants to merge 1 commit into
masterfrom
chuck.hagenbuch/tag-indexing-rule-resources

Conversation

@chuck
Copy link
Copy Markdown
Contributor

@chuck chuck commented Jun 3, 2026

Summary

Adds three new resources for managing Datadog tag indexing rules via Terraform. Tag indexing rules control which tag keys are indexed for custom metrics, reducing cardinality costs while preserving queryability.

DRAFT — blocked on upstream PRs. See blocker section below.

New resources

datadog_tag_indexing_rule

Full CRUD resource. rule_order is computed-only (server assigns max+1 on create); use datadog_tag_indexing_rule_order for atomic re-sequencing.

resource "datadog_tag_indexing_rule" "example" {
  name                = "index-env-service-for-web"
  metric_name_matches = ["web.request.*", "web.latency.*"]
  tags                = ["env", "service"]

  options {
    version = 1
    data {
      manage_preexisting_metrics = true
      override_previous_rules    = false
    }
  }
}

datadog_tag_indexing_rule_exemption

Exempts a specific metric from all tag indexing rules. metric_name and reason are both RequiresReplace (no in-place update; the API has no PATCH endpoint). Read removes state when kind=legacy_tag_configuration since that state is managed via datadog_metric_tag_configuration, not this resource.

resource "datadog_tag_indexing_rule_exemption" "example" {
  metric_name = "my.special.metric"
  reason      = "This metric has a custom tag configuration predating the rule system."
}

datadog_tag_indexing_rule_order

Singleton list resource (modeled on datadog_logs_pipeline_order) that atomically re-sequences all rules. Create and Update both call POST /api/v2/metrics/tag-indexing-rules/order. Delete is a no-op (ordering cannot be deleted from the API).

resource "datadog_tag_indexing_rule_order" "main" {
  name = "main"
  rule_ids = [
    datadog_tag_indexing_rule.catch_all.id,
    datadog_tag_indexing_rule.web.id,
    datadog_tag_indexing_rule.infra.id,
  ]
}

Design notes

  • All three resources use GetMetricsApiV2(), which already exists in api_instances_helper.go.
  • datadog_tag_indexing_rule_exemption.Read explicitly handles the kind=legacy_tag_configuration case by removing the resource from state — this resource only manages explicit exemptions, not implicit ones from legacy tag configurations.
  • datadog_tag_indexing_rule_order.Read calls ListTagIndexingRules and derives order from rule_order field sorted ascending.

Blocker

This PR is blocked on two upstream PRs that add TagIndexingRule* types and methods to datadogV2.MetricsApi:

  1. datadog-api-spec#5837 — adds the spec (approved, awaiting #api-platform merge)
  2. datadog-api-client-go PR (auto-generated once #5837 merges)

Once the client PR merges:

  1. go get github.com/DataDog/datadog-api-client-go/v2@<new-version>
  2. go mod tidy
  3. Remove the NOTE: comments from the three resource files
  4. go build ./... to verify

Test plan

  • Acceptance tests (to be written once client types are available)
  • terraform plan and terraform apply with example configs against staging

🤖 Generated with Claude Code

… [WIP]

Three new Plugin Framework resources backed by the v2 tag-indexing-rule
API endpoints in the Datadog metrics-governance service:

  datadog_tag_indexing_rule
    CRUD resource keyed by UUID. rule_order is computed-only (server-
    assigns max+1 on create). Use datadog_tag_indexing_rule_order to
    control evaluation order atomically.

  datadog_tag_indexing_rule_exemption
    Singleton per metric_name. Exempts a metric from all tag indexing
    rules. Both metric_name and reason are RequiresReplace (no in-place
    update; the API has no PATCH). Read returns nil state when the
    kind=legacy_tag_configuration — that state is managed separately
    via datadog_metric_tag_configuration.

  datadog_tag_indexing_rule_order
    Singleton list resource mirroring datadog_logs_pipeline_order.
    Create and Update both call POST /api/v2/metrics/tag-indexing-
    rules/order (atomic re-sequence). Delete is a no-op. Read derives
    current order from ListTagIndexingRules sorted by rule_order.

NOTE: This PR is a DRAFT blocked on the datadog-api-client-go PR that
will be auto-generated once datadog-api-spec#5837 merges. The build
currently fails with undefined datadogV2.TagIndexingRule* errors.
Once the client PR lands: update go.mod, remove the NOTE comments,
and run go build ./... to verify.

All three resources use GetMetricsApiV2() which already exists in
api_instances_helper.go.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@datadog-datadog-prod-us1-2
Copy link
Copy Markdown

datadog-datadog-prod-us1-2 Bot commented Jun 3, 2026

Pipelines

Fix all issues with BitsAI

⚠️ Warnings

🚦 18 Pipeline jobs failed

Run Tests | all-checks   View in Datadog   GitHub Actions

Run Tests | linter-checks   View in Datadog   GitHub Actions

See error Compilation errors in resource_datadog_tag_indexing_rule.go: method undefined in MetricsApi for GetTagIndexingRule, CreateTagIndexingRule, UpdateTagIndexingRule, DeleteTagIndexingRule and several undefined types like TagIndexingRuleResponse, TagIndexingRuleCreateRequest, and TagIndexingRuleOptions.

Run Tests | test (1.1.5, 0, ubuntu-latest)   View in Datadog   GitHub Actions

See error Detected differences in files requiring formatting. Please run 'gofmt' on the affected files.

View all 18 failed jobs.

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 3cde851 | Docs | Datadog PR Page | Give us feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant